# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Alad Wenter <alad@archlinux.org>
# Contributor: schuay <jakob.gruber@gmail.com>
# Contributor: Daniel J Griffiths <ghost1227@archlinux.us>

pkgname=mc
pkgver=4.8.29
_commit=e99f44c5e7ec2060195239b0448afa27e477a0ff # git rev-parse ${pkgver}
pkgrel=2
pkgdesc='A file manager that emulates Norton Commander'
arch=('loong64' 'x86_64')
url='https://midnight-commander.org/'
license=('GPL')
depends=(
  'e2fsprogs'
  'glib2'
  'gpm'
  'libssh2'
  'slang'
  'which'
)
makedepends=(
  'aspell'
  'git'
  'libxt'
  'libx11'
  'unzip'
)
optdepends=(
  'aspell: spelling corrections'
  'cabextract: ucab extfs'
  'cdparanoia: audio extfs'
  'cdrkit: iso9660 extfs'
  'cvs: CVS support'
  'gawk: hp48+ extfs'
  'mtools: a+ extfs'
  'p7zip: support for 7zip archives'
  'perl: needed by several extfs scripts'
  'python: to access uc1541 or s3 storage'
  'python-boto: s3+ extfs'
  'python-pytz: s3+ extfs'
  'unace: uace extfs'
  'unarj: uarj extfs'
  'unrar: urar extfs'
  'unzip: open zip archives'
  'zip: uzip extfs'
)
backup=(
  'etc/mc/edit.indent.rc'
  'etc/mc/filehighlight.ini'
  'etc/mc/mc.ext'
  'etc/mc/mc.keymap'
  'etc/mc/mc.menu'
  'etc/mc/mcedit.menu'
  'etc/mc/sfs.ini'
)
options=('!emptydirs')
source=(
  #"https://ftp.osuosl.org/pub/midnightcommander/${pkgname}-${pkgver}.tar.xz"
  "git+https://github.com/MidnightCommander/mc.git?signed#tag=${_commit}"
  'mc-python3.patch'
)
sha256sums=('SKIP'
            '78df8592c86445fa6249433e8587889e3923c0bb8b604cae32d5e739d2cc025c')
validpgpkeys=(CC37C2244E2FF0ED548D5DD5F722EE79BCBBE0EF) # Yury V. Zaytsev <yury@shurup.com>

prepare() {
  cd mc

  # port to Python 3
  # ref: https://github.com/MidnightCommander/mc/pull/149
  patch -p1 -i "$srcdir/mc-python3.patch"

  ./autogen.sh
}

build() {
  cd mc

  ./configure \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --sysconfdir=/etc \
    --enable-aspell \
    --with-screen=slang \
    --with-x

  make
}

package() {
  cd mc

  make DESTDIR="$pkgdir" install

  # FS#50889: Replace mc.keymap symlink with target file to fix backup mechanism.
  rm "$pkgdir/etc/mc/mc.keymap"
  cp "$pkgdir"/etc/mc/mc{.default,}.keymap
}
